package day0314;

import com.sun.security.ntlm.Server;

import java.io.*;
import java.net.ServerSocket;
import java.net.Socket;
import java.nio.charset.StandardCharsets;

public class ServerDemo {

    private ServerSocket serverSocket;

    public ServerDemo() {

        try {
            System.out.println("建立服务端");
            serverSocket = new ServerSocket(8088);
            System.out.println("建立完毕");
        } catch (IOException e) {
            e.printStackTrace();
        }

    }
    public void start(){
        try {

            while (true){
                Socket socket = serverSocket.accept();
               // System.out.println("完毕");

                InputStream is =socket.getInputStream();
                InputStreamReader isr= new InputStreamReader(is , StandardCharsets.UTF_8);
                BufferedReader br =new BufferedReader(isr);

                String message;
                while ((message=br.readLine())!=null){
                    System.out.println(socket.getInetAddress()+message);
                }
            }



        } catch (IOException e) {
            e.printStackTrace();
        }

    }

    public static void main(String[] args) {
        ServerDemo sever =new ServerDemo();
        sever.start();
    }
}
